#include "animation_item.h"
#include <lampe/xml/IXMLFactoryEnvironment.h>
#include "irrxml.h"
#include <lampe/xml/IXmlNode.h>
#include <lampe/animation/IAnimation.h>
#include <lampe/animation/IAnimationDB.h>
#include <ISceneManager.h>
#include "../../animation/CAnimationRecord.h"
namespace lampe{
namespace xml{
class AnimationItemFactoryRecord:public IIrrXmlNode{
public:
	AnimationItemFactoryRecord(irr::IrrlichtDevice*d):IIrrXmlNode(d){}
	virtual lampe::xml::TagResult tagHandlerBefor(lampe::xml::IXMLFactoryEnvironment*environment,lampe::xml::IXmlNode*node){
		if (!node->getParent() || !node->getParent()->getTag())
			return lampe::xml::STOP;

		if (node->getAttString("name","")=="")
			return lampe::xml::STOP;

		lampe::animation::IAnimation*anim=(lampe::animation::IAnimation*)node->getParent()->getTag();
		lampe::animation::IAnimationRecord*record=anim->addAnimationFromFile(node->getAttString("href",""),node->getAttString("name",""));
		record->setSpeed(node->getAttF32("speed",30.0f));
		record->setTransitionTime(node->getAttF32("transition",0.2f));
		node->setTag(record);

		return lampe::xml::NEXT;
	}
	
	virtual LAMPE_VECTOR_VENDOR<String> getProcessedTags(){
		LAMPE_VECTOR_VENDOR<String> res;
		res.push_back("animation::record");
		return res;
	};
};

}//namespace xml
}//namespace lampe
void regAnimationItem(lampe::xml::IXMLFactoryEnvironment*environment,irr::IrrlichtDevice*d){
	lampe::xml::AnimationItemFactoryRecord*temp=new lampe::xml::AnimationItemFactoryRecord(d);
	environment->registerHandler(temp);
	temp->drop();
}
